From d1e640d79b4bb2447ba044712d207e50fec4669b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 11 Mar 2016 12:05:58 -0800 Subject: [PATCH] Improve the error message for missing path overrides Closes #2457 --- src/cargo/ops/cargo_compile.rs | 14 +++++++++----- src/cargo/ops/cargo_read_manifest.rs | 6 +++++- tests/test_cargo_compile_path_deps.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 1ac229885..ad82d4f77 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -34,7 +34,7 @@ use core::resolver::{Method, Resolve}; use ops::{self, BuildOutput, ExecEngine}; use sources::PathSource; use util::config::Config; -use util::{CargoResult, profile}; +use util::{CargoResult, profile, human, ChainError}; /// Contains information about how a package should be compiled. pub struct CompileOptions<'a> { @@ -393,17 +393,21 @@ fn add_overrides<'a>(registry: &mut PackageRegistry<'a>, // The path listed next to the string is the config file in which the // key was located, so we want to pop off the `.cargo/config` component // to get the directory containing the `.cargo` folder. - p.parent().unwrap().parent().unwrap().join(s) - }).filter(|p| { + (p.parent().unwrap().parent().unwrap().join(s), p) + }).filter(|&(ref p, _)| { // Make sure we don't override the local package, even if it's in the // list of override paths. cur_path != &**p }); - for path in paths { + for (path, definition) in paths { let id = try!(SourceId::for_path(&path)); let mut source = PathSource::new_recursive(&path, &id, config); - try!(source.update()); + try!(source.update().chain_error(|| { + human(format!("failed to update path override `{}` \ + (defined in `{}`)", path.display(), + definition.display())) + })); registry.add_override(&id, Box::new(source)); } Ok(()) diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index ddaace342..445a356c4 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -87,7 +87,11 @@ fn walk(path: &Path, callback: &mut FnMut(&Path) -> CargoResult) Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => { return Ok(()) } - Err(e) => return Err(From::from(e)), + Err(e) => { + return Err(human(e)).chain_error(|| { + human(format!("failed to read directory `{}`", path.display())) + }) + } }; for dir in dirs { let dir = try!(dir); diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index 5cd97d301..58dbf4369 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -838,3 +838,30 @@ test!(override_and_depend { {compiling} b v0.5.0 ([..]) ", compiling = COMPILING))); }); + +test!(missing_path_dependency { + let p = project("foo") + .file("Cargo.toml", r#" + [project] + name = "a" + version = "0.5.0" + authors = [] + "#) + .file("src/lib.rs", "") + .file(".cargo/config", r#" + paths = ["../whoa-this-does-not-exist"] + "#); + p.build(); + assert_that(p.cargo("build"), + execs().with_status(101) + .with_stderr("\ +failed to update path override `[..]../whoa-this-does-not-exist` \ +(defined in `[..]`) + +Caused by: + failed to read directory `[..]` + +Caused by: + [..] (os error [..]) +")); +}); -- 2.30.2